import { useMutation } from '@apollo/client';
import { TWxConfigQuery } from '../utils/type';
import { GET_WXPAY_CONFIG } from '../graphql/order';

export const useWxpayConfig = () => {
  const [get, { loading }] = useMutation<TWxConfigQuery>(GET_WXPAY_CONFIG);

  const getWxConfig = async (
    productId: string,
    quantity: number,
    amount: number,
  ) => {
    const res = await get({
      variables: {
        productId,
        quantity,
        amount,
      },
    });
    return res.data?.getWxpayConfig.data;
  };

  return {
    getWxConfig,
    loading,
  };
};

/**
 * mock 订单数据
 */
// export const useMockOrder = () => {
//   const [get, { loading }] = useMutation([]);

//   const getHandler = async (
//     productId: string,
//     quantity: number,
//     amount: number,
//   ) => {
//     const res = await get({
//       variables: {
//         productId,
//         amount,
//         quantity,
//       },
//     });

//     return res.data?.mockOrderGenerator.data;
//   };

//   return {
//     get: getHandler,
//     loading,
//   };
// };
